<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>添加角色</title>
    <link rel="stylesheet" th:href="@{/webjars/bootstrap/5.1.3/css/bootstrap.min.css}">
</head>
<body>
    <div class="container mt-4">
        <div class="card">
            <div class="card-header">
                <h2>添加角色</h2>
            </div>
            <div class="card-body">
                <form id="addForm" class="mt-3">
                    <div class="mb-3">
                        <label for="name" class="form-label">角色名称</label>
                        <input type="text" class="form-control" id="name" name="name" required>
                    </div>
                    <div class="mb-3">
                        <label for="description" class="form-label">描述</label>
                        <textarea class="form-control" id="description" name="description" rows="3"></textarea>
                    </div>
                    <button type="submit" class="btn btn-primary">提交</button>
                    <a href="/role/list" class="btn btn-secondary">返回</a>
                </form>
            </div>
        </div>
    </div>

    <script th:src="@{/webjars/bootstrap/5.1.3/js/bootstrap.bundle.min.js}"></script>
    <script>
        document.getElementById('addForm').onsubmit = function(e) {
            e.preventDefault();
            const formData = new FormData(this);
            const data = Object.fromEntries(formData.entries());
            
            fetch('/role/add', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded'
                },
                body: new URLSearchParams(data)
            })
            .then(response => response.text())
            .then(result => {
                if (result === 'success') {
                    alert('添加成功');
                    window.location.href = '/role/list';
                } else {
                    alert('添加失败');
                }
            });
        };
    </script>
</body>
</html> 